package tech.dongliang.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.dongliang.system.dao.SysUserRoleDao;
import tech.dongliang.system.model.SysUserRole;
import tech.dongliang.system.service.ISysUserRoleService;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xdzhang
 * @since 2019-01-18
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleDao, SysUserRole> implements ISysUserRoleService {

    @Override
    public List<Integer> getUserRoleId(Integer userId) throws Exception {
        return baseMapper.getUserRoleId(userId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveUserRole(Integer userId, List<Integer> roleIds) {
        try {
            baseMapper.removeByUserId(userId);
            baseMapper.insertRole(userId, roleIds);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
